﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Abs.App.Admin
{
    public partial class Create_Room : System.Web.UI.Page
    {
        Abs.Core.Management.RoomManagement roomManagement;
        protected void Page_Load(object sender, EventArgs e)
        {
            //Kicks the non admin accounts out
            if (Session["Role"] == null)
                Response.Redirect("/User/Unauthorized_Access.aspx");
            if ((int)Session["Role"] == (int)Abs.Core.Models.User.RoleEnum.User)
                Response.Redirect("/User/Unauthorized_Access.aspx");
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
            roomManagement = Abs.Core.Management.Manage.Room;
            if (!roomManagement.CreateRoom(Text_Name.Text))
            {
                Response.Redirect("/Default.aspx");
            }
            int roomId = roomManagement.RoomIdentity;

            for (int i = 0; i < Days.Items.Count; i++)
            {
                if (Days.Items[i].Selected)
                {
                    switch (Days.Items[i].Text)
                    {
                        case "Monday":
                            if (!roomManagement.CreateRoomSchedule(roomId, (int)DayOfWeek.Monday, Start_Time.Text, Last_Time.Text))
                            {
                                Response.Redirect("/Default.aspx");
                            }
                            break;

                        case "Tuesday":
                            if (!roomManagement.CreateRoomSchedule(roomId, (int)DayOfWeek.Tuesday, Start_Time.Text, Last_Time.Text))
                            {
                                Response.Redirect("/Default.aspx");
                            }
                            break;
                        case "Wednesday":
                            if (!roomManagement.CreateRoomSchedule(roomId, (int)DayOfWeek.Wednesday, Start_Time.Text, Last_Time.Text))
                            {
                                Response.Redirect("/Default.aspx");
                            }
                            break;
                        case "Thursday":
                            if (!roomManagement.CreateRoomSchedule(roomId, (int)DayOfWeek.Thursday, Start_Time.Text, Last_Time.Text))
                            {
                                Response.Redirect("/Default.aspx");
                            }
                            break;
                        case "Friday":
                            if (!roomManagement.CreateRoomSchedule(roomId, (int)DayOfWeek.Friday, Start_Time.Text, Last_Time.Text))
                            {
                                Response.Redirect("/Default.aspx");
                            }
                            break;
                        case "Saturday":
                            if (!roomManagement.CreateRoomSchedule(roomId, (int)DayOfWeek.Saturday, Start_Time.Text, Last_Time.Text))
                            {
                                Response.Redirect("/Default.aspx");
                            }
                            break;

                    }

                }
            }
            Response.Redirect("/Admin/Room_Creation_Success.aspx");
        }
    }
}